package com.wits.qso.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import net.sf.json.JSONObject;

import com.wits.platform.entity.BaseEntity;

@Entity
@Table(name="qso_class")
public class Cls extends BaseEntity {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 8654246681359891318L;

	/** 班级编号 **/
	private String clsId;
	
	/** 班级名称 **/
	private String clsTitle;
	
	private Dept dept = null;
	private Grade grade = null;	
	
	@Id
	@GenericGenerator(name = "idGen", 
					strategy = "com.wits.platform.common.id.generator.IDGenerator",
					parameters={ 
								@Parameter(name = "segment_value", value = "QSO_CLS_ID"), 
								@Parameter(name="table_name",value="wits_id_generator"),
								@Parameter(name="value_column_name",value="gen_value"),
								@Parameter(name="segment_column_name",value="gen_name"),
								@Parameter(name="segment_value_length",value="5"),
								@Parameter(name="sq_format",value="%03d"), 
								@Parameter(name="sq_prefix",value="CL") 
					})
	@GeneratedValue(generator = "idGen")
	@Column(name = "cls_id", nullable = false, insertable = true, updatable = false, length = 5)
	public String getClsId() {
		return clsId;
	}

	public void setClsId(String clsId) {
		this.clsId = clsId;
	}

	@Column(name="cls_title",length=50)
	public String getClsTitle() {
		return clsTitle;
	}

	public void setClsTitle(String clsTitle) {
		this.clsTitle = clsTitle;
	}
	
	@ManyToOne
	@JoinColumn(name = "cls_dptid")
	public Dept getDept() {
		return dept;
	}

	@ManyToOne
	@JoinColumn(name = "cls_gradeid")
	public Grade getGrade() {
		return grade;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}

	public void setGrade(Grade grade) {
		this.grade = grade;
	}

	@Override
	public String display() {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public String toString(){
		return "{\"clsId\":\"" + this.clsId 
				+ "\",\"clsTitle\":\"" + this.clsTitle
				+ "\",\"deptTitle\":\"" + getDept().getTitle()
				+ "\",\"gradeTitle\":\""+ getGrade().getGradeTitle()
				+ "\"}";
	}
}
